<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    {{--<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />--}}
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="{{asset('xAdmin/css/font.css')}}">
    <link rel="stylesheet" href="{{asset('xAdmin/css/xadmin.css')}}">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="{{asset('xAdmin/lib/layui/layui.js')}}" charset="utf-8"></script>
    <script type="text/javascript" src="{{asset('xAdmin/js/xadmin.js')}}"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">
    <form class="layui-form" id="edit-theme">
        {{csrf_field()}}
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>主题名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name" lay-verify="required"
                       autocomplete="off" value="{{$info['name']}}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="phone" class="layui-form-label">
                描述
            </label>
            <div class="layui-input-inline">
                <textarea name="description" placeholder="请输入" class="layui-textarea">{{$info['description']}}</textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_email" class="layui-form-label">
                显示客户端
            </label>
            <div class="layui-input-inline">
                <select name="belong_to">
                    <option @if($info['belong_to'] == 0) selected @endif value="0">全部显示</option>
                    <option @if($info['belong_to'] == 1) selected @endif value="1">App</option>
                    <option @if($info['belong_to'] == 2) selected @endif value="2">PC</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="edit" lay-submit="">
                保存
            </button>
        </div>
    </form>
</div>
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        let form = layui.form,
            layer = layui.layer;

        //自定义验证规则
        form.verify({
            name: function(value){
                if(value.length < 2){
                    return '主题至少得2个字符啊';
                }
            },
        });

        //监听提交
        form.on('submit(edit)', function(){
            $.ajax({
                url: '{{url("backstage/editTheme", ['id' => $info->id])}}',
                type: 'POST',
                dataType: 'json',
                data: $('#edit-theme').serialize(),
                success: function (result) {
                    if (result.status === 0) {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 2000
                        }, function () {
                            // 获得frame索引
                            let index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }
                },
                error: function () {
                    layer.msg('保存异常，请重试！');
                    return false;
                }
            });
            return false;
        });
    });
</script>

</body>

</html>
